<?php
namespace Orm\SharingLog;

use Base\Exception\RmException;
class SharingLogClass extends \Base\BaseOrmObject{
    protected   $id,
				$user_id = 0, // 用户id
				$that_day = '', // 日期
				$share_goals = 0, // 分享目标 1.群组或者朋友 2.朋友圈
				$title = '', // 分享标题
				$desc = '', // 分享描述
				$link = '', // 分享链接
				$imgUrl = '', // 分享图标  
				$is_del = 0,
				$insert_time = '',
				$update_time = '';

    function __init($data)
    {
        parent::__init($data);
        $this->dformat($data);
    }

    private function dformat()
    {
    }

    public function loadById($id = 0)
    {
        $model = new \Orm\SharingLog\SharingLogModel();
        $data = $model->loadById($id);
        self::__init($data);
    }

    public function insert()
    {
        $this->checkNecessaryParam();
        $data = array(
            'user_id' => $this->user_id,
			'that_day' => $this->that_day,
			'share_goals' => $this->share_goals,
			'title' => $this->title,
			'desc' => $this->desc,
			'link' => $this->link,
			'imgUrl' => $this->imgUrl,
        );

        $model = new \Orm\SharingLog\SharingLogModel();
        $model->insert($data);
        $this->id = $model->getLastId();
    }

    public function update()
    {
        $this->checkNecessaryParam();
        $data = array(
            'user_id' => $this->user_id,
			'that_day' => $this->that_day,
			'share_goals' => $this->share_goals,
			'title' => $this->title,
			'desc' => $this->desc,
			'link' => $this->link,
			'imgUrl' => $this->imgUrl,
        );

        $model = new \Orm\SharingLog\SharingLogModel();
        $model->update($data, "`id` = {$this->id}");
    }

    public function delete($id)
    {
        $data = array('is_del'=>1);
        $model = new \Orm\SharingLog\SharingLogModel();
        $model->update($data, "`id` = {$id}");
    }

    private function checkNecessaryParam()
    {
    }

    public static function getShareGoals($share_goals){
        $share = '';
        switch ($share_goals){
            case '1':$share = '群组或者朋友';break;
            case '2':$share = '朋友圈';break;
        }
        return $share;
    }
}